package com.skt.common_hr.babybt.model
{
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.common.utilSilver.textSilver;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.collections.ArrayCollection;

	public class BabybtApprovalProxy4 extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "BabybtApprovalProxy4";
		public var dataProvider:ArrayCollection;

		private var _bAppType:Boolean = false;		// 정산 포함여부
		private var _amount:Number;
		
		public var BabybtObj:Object;
		
		private var templateHTML1:String = "";
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function BabybtApprovalProxy4(data:Object=null)
		{
			super(NAME, data);
			loadTemplate1();
		}
		
		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}
		
		public function get title():String 
		{
			var tmp:String;
			tmp = "휴일/야간OT 근로 신청";	
/* 			tmp = "구성원 포상 (";			
			tmp += BabybtObj.AWDDT + ", " + BabybtObj.ENAME;  			
			tmp += ")"; */
			return tmp;
		}
		


		public function get content():String
		{
			return buildHTML();
		}
		
		public function get appCode():String 
		{
			return "16"; 	//
		}
 		
 		private function loadTemplate1():void
		{
			var loader:URLLoader = new URLLoader();
			var request:URLRequest = new URLRequest("assets/template/Babybt_ot.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}
 		
		
		private function templateResult(event:Event):void
		{
			templateHTML1 = event.target.data;
		}
		
		

		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}


		private function buildHTML():String
		{
			var htmlAll:String = templateHTML1;
			var htmlBlock:String = "";
			
			var ptnPERNR:RegExp  		= /__PERNR__/; 
								
//			var ptnENAME:RegExp  		= /__ENAME__/;
//			var ptnORGTX:RegExp  		= /__ORGTX__/;

			//var ptnBEGDA:RegExp  		= /__BEGDA__/;			// 임신일 ,   			
			var ptnENDDA:RegExp  		= /__ENDDA__/;			 // 출산 예정일 ,   출산예정일 :        년       월      일 (현재 임신     주차)
			var ptnBIRDD:RegExp  		= /__BIRDD__/;			// 출산일 ,   출   산   일 :        년      월      일 (현재 출산 후    월째)
			

			
			var ptnCYES1:RegExp  		= /__CYES1__/;
			var ptnCYES2:RegExp  		= /__CYES2__/;
			var ptnCYES3:RegExp  		= /__CYES3__/;
			
			var ptnCYES1N:RegExp  		= /__CYES1N__/;
			var ptnCYES1H:RegExp  		= /__CYES1H__/;
			var ptnCYES2N:RegExp  		= /__CYES2N__/;
			var ptnCYES2H:RegExp  		= /__CYES2H__/;
			
			
			
			var sBIRDD:String 	= '출산예정일 :               (현재 임신   주차)';
			var sENDDA:String 	= '출   산   일 :               (현재 출산 후   월째)';
			
			if(BabybtObj.O_WEEK !='') {
				sBIRDD = '출산예정일 : ' + textSilver.toDotKorString(BabybtObj.BIRDD_DATE) +" (현재 임신 " + BabybtObj.O_WEEK +"  주차)";	
			}
			else if(BabybtObj.O_MON !='') {
				sENDDA  = '출   산   일 : ' + textSilver.toDotKorString(BabybtObj.ENDDA_DATE) +" (현재 출산 후 " + BabybtObj.O_MON +"  월째)";
			}
			
			
			//var sTime:String = BabybtObj.BEGUZ + " ~ " + BabybtObj.ENDUZ;
			
			htmlAll = htmlAll.replace(ptnPERNR		, BabybtObj.PERNR);
			htmlAll = htmlAll.replace(ptnBIRDD		, sBIRDD);
			htmlAll = htmlAll.replace(ptnENDDA		, sENDDA);
						
//			htmlAll = htmlAll.replace(ptnBEGDA		, sBEGDA);
	
			
			htmlAll = htmlAll.replace(ptnCYES1		, BabybtObj.CYES1=='X'?'checked':'');
			htmlAll = htmlAll.replace(ptnCYES2		, BabybtObj.CYES2=='X'?'checked':'');
			htmlAll = htmlAll.replace(ptnCYES3		, BabybtObj.CYES3=='X'?'checked':'');
			
			htmlAll = htmlAll.replace(ptnCYES1N		, BabybtObj.CYES1N=='X'?'checked':'');
			htmlAll = htmlAll.replace(ptnCYES1H		, BabybtObj.CYES1H=='X'?'checked':'');
			htmlAll = htmlAll.replace(ptnCYES2N		, BabybtObj.CYES2N=='X'?'checked':'');
			htmlAll = htmlAll.replace(ptnCYES2H		, BabybtObj.CYES2H=='X'?'checked':'');			
			return htmlAll;
		}
	}
}